#include <stdio.h>
int binsearch(int x, int v[], int n)
{ 		      
    int low, high, mid;

    low = -1;
    high = n;
    while (low + 1 < high)
    { 		      
        mid = (low + high) / 2;
        if (v[mid] < x)
            low = mid;
        else
            high = mid;
    }
    if (high == n || v[high] != x)
        return -1;
    else
        return high;
} 		      

int main(void)
{ 		      
    int test[80];
    printf("Please input the array size:");
    int n;
    scanf("%d", &n);
    printf("Please input the array data:");
    int i ;
    for (i = 0; i < n; i++)
    { 		      
        scanf("%d", &test[i]);
    }
    printf("Please input the wanted search data:");
    int x;
    scanf("%d", &x);
    printf("looking for %d. Index=%d\n", x, binsearch(x, test, n ));
    return 0;

} 		   